

function findAllSubclasses(parentClassName) {
  if (!ObjC.available) return [];
  
  const parentClass = ObjC.classes[parentClassName];
  if (!parentClass) {
    console.log(`[错误] 父类 ${parentClassName} 未找到`);
    return [];
  }

  const subclasses = [];
  const parentClassPtr = parentClass.handle;

  // 遍历所有已加载类
  ObjC.enumerateLoadedClasses({
    onMatch: function(className) {
      const currentClass = ObjC.classes[className];
      
      // 检查继承关系
      let superClass = currentClass.$superClass;
      while (superClass) {
        if (superClass.handle.equals(parentClassPtr)) {
          subclasses.push(className);
          break;
        }
        superClass = superClass.$superClass;
      }
    },
    onComplete: function() {
      console.log(`\n=== ${parentClassName} 的子类 (共 ${subclasses.length} 个) ===`);
      subclasses.forEach((name, i) => console.log(`${i+1}. ${name}`));
    }
  });

  return subclasses;
}

// 使用示例：查找 UIViewController 的所有子类
findAllSubclasses("UIView");